package service.group;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import object.Group;

import service.CommonServlet;

public class GetGroups extends CommonServlet {
	
	@Override
	protected void execute(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		try
		{
			String sql = "select * from f_group where u_no = ?";
			PreparedStatement pstmt = mConnection.prepareStatement(sql);
			pstmt.setInt(1, uNo);
			ResultSet rs = pstmt.executeQuery();
			List<Group> groups = new ArrayList<Group>();
			while(rs.next())
			{
				Group group = new Group();
				group.setgNo(rs.getInt("g_no"));
				group.setgName(rs.getString("g_name"));
				groups.add(group);
			}
			sendObject(groups, response);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	/**
	 * Constructor of the object.
	 */
	public GetGroups() {
		super();
	}

}
